<template>
	<view class="content">
		<u-sticky bgColor="#fff">
			<u-tabs :list="list1" lineColor="rgba(243, 39, 28, 1)" :current="currenttabtow" @click="clicktabtow"
				:activeStyle="{
		    	    color: '#000000',
		    	    fontWeight: 'bold',
		    	    transform: 'scale(1.05)'
		    	}" :inactiveStyle="{
		    	            color: 'rgba(102, 102, 102, 1)',
		    				fontWeight: 'bold',
		    	            transform: 'scale(1)'
		    	        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;"></u-tabs>
		</u-sticky>
		<view class="padding_lrb">
			<view class="ffffff padding border_2 margin_top" v-for="item in list.data" :key="item.id"
				@click="goOrderInfo(item.id)">
				<view class="flexbetween">
					<view class="flexleft">
						<image class="imgShop margin_right1" src="/static/image/mine/dianpuRed.png" mode="widthFix"></image>
						<view class="color_ling text_z margin_right1">{{item.shop.shop_name}}</view>
						<u-icon name="arrow-right" color="rgba(153, 153, 153, 1)" size="12"></u-icon>
					</view>
					<!-- 普通订单 -->
					<view class="huangsetext" style="color:#000000;" v-show="item.state==-1">已取消</view>
					<view class="hongsetext" style="color: rgba(255, 168, 0, 1);" v-show="item.state==1">待付款</view>
					<view class="hongsetext" style="color: rgba(255, 168, 0, 1);" v-show="item.state==2">待分享
						{{item.state_text2}}
					</view>
					<view class="huangsetext" style="color:rgba(212, 139, 57, 1);" v-show="item.state==3">待发货</view>
					<view class="huangsetext" style="color:rgba(212, 139, 57, 1);" v-show="item.state==4">待收货</view>
					<view class="huangsetext" style="color:rgba(212, 139, 57, 1);" v-show="item.state==5">待评价</view>
					<view class="huangsetext" style="color:rgba(19, 196, 99, 1);" v-show="item.state==6">已完成</view>
					<view class="huangsetext" style="color:rgba(19, 196, 99, 1);" v-show="item.state==8">已退款</view>
				</view>
				<view class="flexbetween xiahuax margin_top" v-for="ite in item.ordergoods" :key="ite.id">
					<view class="shilitu">
						<image :src="ite.goods_image_text" mode="widthFix"></image>
					</view>
					<view class="" style="width: 74%;">
						<view class="yihang text_zi">{{ite.goods_name}}</view>
						<view class="baise">{{ite.sku}}</view>
						<view class="flexbetween">
							<view class="qianshu">¥{{item.activity_type==1?ite.price:ite.alone_price}}</view>
							<view class="shuliang">X{{ite.goods_num}}</view>
						</view>
					</view>
				</view>
				<view class="flexright margin_top">
					<view class="nostrongtext margin_right1">共计<text class="ershisi">{{item.total_num}}</text>件商品</view>
					<view class="nostrongtext">合计<text class="ershisi">￥{{item.pay_price}}</text></view>
				</view>
				<!-- 所有按钮 -->
				<view class="flexright margin_top">
					<view class="huisebtn" v-show="item.can_cancel" @click.stop="cancelorder(item.id)">取消订单
					</view>
					<view class="huangsebtn margin_left3" v-show="item.can_pay" @click.stop="atoncePay(item)">立即付款
					</view>
					<view class="huisebtn margin_left3" v-show="item.can_buyfull" @click.stop="atonceAllPay(item)">全款购买
					</view>
					<!-- 分享到微信、QQ -->
					<view class="huangsebtn margin_left3" v-show="item.can_share" @click.stop="onceShare(item.id)">立即分享
					</view>
					<view class="huisebtn margin_left3" v-show="item.can_express"
						@click.stop="goLogisticsInfo(item.id)">查看物流</view>
					<view class="huisebtn marginleft3" v-show="item.can_refund" @click.stop="goApplyRefund(item.id)">
						退货/售后</view>
					<view class="huangsebtn marginleft3" v-show="item.can_receipt" @click.stop="suresh(item.id)">确认收货
					</view>
					<view class="huangsebtn margin_left3" v-show="item.can_comment" @click.stop="evaluate(item.id)">立即评价
					</view>
					<view class="huisebtn marginleft3" v-show="item.can_del"
						@click.stop="deletorder(item.id)">删除订单</view>
				</view>
			</view>
			<view class="flexcenter placeholderBoxTop" v-if="!list.data.length">
				<image class="placeholderBox" src="/static/placeholderimg.png" mode="widthFix"></image>
			</view>
		</view>
		<u-popup :show="show" mode="center" @close="show=false">
			<view class="popupBox">
				<view class="title">分享拼单</view>
				<view class="text_g color_ling margin_top4">
					还差<text
						style="color: rgba(243, 39, 28, 1);">{{shareInfo.groupbuyingdata.buying_total_num - shareInfo.groupbuyingdata.buying_now_num}}</text>人，赶快邀请好友拼单吧
				</view>
				<view class="margin_top5 flexbetween">
					<view class="text" @click="wxShareFriends">
						<image class="imgBox" src="/static/image/home/weixin.png" mode="widthFix"></image>
						<view class="text_b color_ling margin_top2">微信好友</view>
					</view>
					<view class="text" @click="qqShareFriends">
						<image class="imgBox" src="/static/image/home/QQ.png" mode="widthFix"></image>
						<view class="text_b color_ling margin_top2">QQ好友</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		
		<!-- 物流单号弹出框 -->
		<u-popup :show="wlinfoShow" mode="center" @close="wlinfoShow=false" :round="15">
			<view class="text dan">
				<text class="wuliu">物流单号</text>
				<view class="zhongtong">
					<view class="">{{express_name}}</view>
					<view class="text margin_top1">{{express_no}}</view>
				</view>
				<view class="fuzhi">
					<view class="copy" @click="copy">点击复制</view>
				</view>
			</view>
		</u-popup>
		
		
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				columns: [],
				currenttabtow: 0, //0全部，1待付款，2待分享， 3待发货，4待收货，5已完成
				list1: [{
						name: '全部',
					},
					{
						name: '待付款',
					},
					{
						name: '待分享',
					},
					{
						name: '待发货',
					},
					{
						name: '待收货',
					},
					{
						name: '待评价',
					},
					{
						name: '已完成',
					}
				],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				orderDetail: {}, // 订单详情内容
				shareInfo: {
					groupbuyingdata: {}
				}, //拼团详情
				shareId: "", //拼团订单id
				express_name:'',
				express_no:'',
				wlinfoShow:false,
			}
		},
		onLoad(options) {
			this.currenttabtow = options.value
		},
		onShow() {
			this.init()
		},
		methods: {
			// 跳转 立即评价
			evaluate(id) {
				uni.navigateTo({
					url: "/pages_mine/reportEvaluate?type=1&id=" + id
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request("/api/goods_order/orderlist", 'GET', {
					page: page || 1,
					state: _this.currenttabtow
				}, false, false, true).then(res => { //我的订单接口
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page)
			},
			atoncePay(item) { // 支付
				let obj = {
					order_id: item.id,
					total_price: item.total_price
				}
				uni.navigateTo({
					url: '/pages_index/payment?msg1=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			atonceAllPay(item) { // 全款购买
				let obj = {
					order_id: item.id,
				}
				uni.navigateTo({
					url: '/pages_index/payment?msg2=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			onceShare(id) { //立即分享
				let _this = this;
				_this.shareId = id
				httpRequest.request("/api/goods_order/groupshare", 'POST', {
					order_id: id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						_this.shareInfo = res.data
					} else {
						httpRequest.toast(res.msg);
					}
					_this.show = true
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			wxShareFriends() { //微信分享
				let _this = this
				uni.share({
					provider: "weixin",
					type: 0,
					title: "快来跟我拼单",
					href: `https://hongniaotianxuan.com/h5/#/?order_id=${_this.shareId}`,
					scene: "WXSceneSession",
					summary: _this.shareInfo.info.name,
					imageUrl: "https://hongnwh-1318979827.cos.ap-shanghai.myqcloud.com/uploads/20230803/49aef582328737659ba0ef126c7de37a.png",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
						httpRequest.toast("分享成功！");
						_this.show = false
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			qqShareFriends() { //QQ分享
				let _this = this
				let url = `https://hongniaotianxuan.com/h5/#/?order_id=${_this.shareId}`
				uni.share({
					provider: "qq",
					type: 1,
					title: "快来跟我拼单",
					href: url,
					summary: _this.shareInfo.info.name,
					// imageUrl:"www.wanxiangshide.xyz/uploads/20230722/68c2959eb3a63faff5248380f80bc5c1.png",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
						httpRequest.toast("分享成功！");
						_this.show = false
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			goCollageInfo() { //跳转拼团详情
				uni.navigateTo({
					url: "./collageInfo?id=" + this.shareId
				})
			},
			goLogisticsInfo(id) { //查看物流
				// uni.navigateTo({
				// 	url: "/pages_mine/logisticsInfo?type=3&id=" + id
				// })
				
				let _this=this;
				var url = "/api/goods_order/express"
				var data = {
					order_id:id
				}
				
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					
					
					if(res.code==1){
						
						
						
						_this.express_no=res.data.express_no;
						_this.express_name=res.data.express_name;
						
						_this.wlinfoShow = true;
					}else{
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err=>{
					httpRequest.toast(err.msg)
				})
				
				
				
			},
			
			
			
			// 点击复制
			copy() {
				let value = "物流名称：" + this.orderDetail.express_name + " 单号：" + this.orderDetail.express_no
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => {
						//复制成功的回调函数
						httpRequest.toast("复制成功")
						this.show = false
					}
				});
			},
			goApplyRefund(id) { //退货/售后
				uni.navigateTo({
					url: "/pages_mine/applyRefund?id=" + id
				})
			},

			// 取消订单
			cancelorder(id) {
				httpRequest.modal('提示', '确定取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/cancelorder', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 确认收货
			suresh(id) {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/receipt', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 删除订单
			deletorder(id) {
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/del', 'POST', {
							order_id:id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			goOrderInfo(id) { //订单详情
				uni.navigateTo({
					url: "/pages_mine/businessOrderInfo?id=" + id
				})
			},
			clicktabtow(e) {
				this.currenttabtow = e.index;
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	// ::v-deep.u-tabs__wrapper__nav__item {
	// 	//平均分配
	// 	flex: 1;
	// }
	.imgShop {
		width: 26.62rpx;
		height: 24rpx;

	}

	.fuzhi {
		margin: 0rpx 30rpx 30rpx 30rpx;
	}

	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.zhongtong {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
		margin: 87rpx 0rpx 0rpx 0rpx;
	}

	.copy {
		padding: 25rpx 150rpx;
		border-radius: 51rpx;
		background-color: RGBA(225, 159, 83, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.text_zi {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.number {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.nostrongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.baise {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		margin: 12rpx 0rpx;
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.ershisi {
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.qianshu {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: rgba(243, 39, 28, 1);
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;
 overflow: hidden;
		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.lvsetext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #00C058;
	}

	.huangsetext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: RGBA(255, 117, 16, 1);
	}

	.hongsetext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: RGBA(255, 117, 16, 1);
	}

	.marginleft3 {
		margin-left: 30rpx;
	}

	::v-deep.u-popup__content {
		background: #FAFAFA;
		border-radius: 30rpx 30rpx 30rpx 30rpx;
	}

	.popupBox {
		padding: 65rpx 95rpx;

		.title {
			font-size: 40rpx;
			font-family: PingFang SC-Heavy, PingFang SC;
			font-weight: 800;
			color: #000000;
			text-align: center;
		}

		.imgBox {
			width: 112rpx;
			height: 112rpx;
		}
	}
</style>